<template>
  <div>
    <!--面包屑导航-->
    <Breadcrumb>
      <template #firstTitle>
        <span>数据统计</span>
      </template>
      <template #secondTitle>
        <span>数据报表</span>
      </template>
    </Breadcrumb>
    <!--卡片视图-->
    <el-card>
      <div id="main" style="width: 800px;height:400px;"></div>
    </el-card>
  </div>
</template>

<script>
  import Breadcrumb from '@/components/common/Breadcrumb.vue'
  import echarts from 'echarts'
  export default {
    name: "Reports",
    data() {
      return {
        dataList: []
      }
    },
    components: {
      Breadcrumb
    },
    mounted() {
      this.createChart();
    },
    methods: {
      async createChart() {
        const {data: res} = await this.$http.get('reports/type/1');
        // console.log(res);
        if (res.meta.status !== 200) {
          this.$message.error(`获取数据报表: ${res.meta.msg}`);
          return;
        }
        this.dataList = res.data;

        // 基于准备好的dom，初始化echarts实例
        const myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        let option = {
          title: {
            text: '用户来源'
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              label: {
                backgroundColor: '#6a7985'
              }
            }
          },
          legend: this.dataList.legend,
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              boundaryGap: false,
              data: this.dataList.xAxis[0].data
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          series: this.dataList.series
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      }
    }
  }
</script>

<style scoped>

</style>
